package com.dingli.service.impl;

import com.dingli.framework.entity.Resume;
import com.dingli.framework.entity.Train;
import com.dingli.framework.entity.Undertake;
import com.dingli.framework.mapper.TrainMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.ITrainService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainService implements ITrainService {

    @Autowired
    private TrainMapper trainMapper;


    @Override
    public Response<PageInfo<Train>> TRAIN_selectList(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Train> info = new PageInfo<>(trainMapper.TRAIN_selectList(search));
        return new Response<>(200, "success", info);
    }

    @Override
    public Response<List<Train>> TRAIN_selectAll(Long tnId) {
        return new Response<>(200,"success",trainMapper.TRAIN_selectAll(tnId));
    }

    @Override
    public Response<Long> TRAIN_insert(Train train) {
        int count = trainMapper.TRAIN_insert(train);
        if (count > 0) {
            return new Response(200, "success", train.getEseId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRAIN_updateById(Train train) {
        int count = trainMapper.TRAIN_updateById(train);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRAIN_deleteById(Long tnId) {
        int count = trainMapper.TRAIN_deleteById(tnId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRAIN_updateState(String tnId) {
        int count = trainMapper.TRAIN_updateState(tnId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRAIN_update(String tnId) {
        int count = trainMapper.TRAIN_update(tnId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<List<Train>> TRAIN_selectState(String tnState) {
        List<Train> trains= trainMapper.TRAIN_selectState(tnState);
        return new Response<>(200,"success", trainMapper.TRAIN_selectState(tnState));
    }

    @Override
    public Response<List<Train>> TRAIN_selectState1(String tnState) {
        List<Train> trains = trainMapper.TRAIN_selectState1(tnState);
        return new Response<>(200,"success", trainMapper.TRAIN_selectState1(tnState));
    }

    @Override
    public Response<List<Train>> TRAIN_All(String tnId) {
        return new Response<>(200,"success", trainMapper.TRAIN_All(tnId));
    }
}
